import http from '@/utils/http'
import {ConfigResp, DynamicsConfigResp} from './types/config'
import {AnyObject} from "@/types/global";
/**
 * 查询请求体
 */
export interface QueryRequest {
    name?: string;
    code?: string;
}
/**
 * 查询响应
 */
export interface QueryResponse extends ConfigResp {}


/**
 * 更新请求体
 */
export interface UpdateRequest {
    id?: number;
    sort?: number;
    name?: string;
    code?: string;
    note?: string;
}


/**
 * 查询响应
 */
export interface DynamicsConfigQueryResponse extends DynamicsConfigResp {}

/**
 * 查询列表
 */
export function getList(params: QueryRequest)  {
    return http.get<PageRes<QueryResponse[]>>('/admin/config/index', params)
}

/**
 * 通过 id 新增更新数据
 */
export function updateRows(request: UpdateRequest) {
    return http.put('/admin/config/edit', request);
}
/**
 * 通过 id 删除数据
 */
export function deleteRows(id: number) {
    return http.post('/admin/config/delete', { id })
}

/**
 * 查询动态配置
 */
export function getConfigData(params: QueryRequest)  {
    return http.get<DynamicsConfigQueryResponse[]>('/admin/config/configData', params)
}

/**
 * 更新配置值
 */
export function editConfigData(request: AnyObject)  {
    return http.post('/admin/config/editConfigData', request);
}